   //初始化订单一级表格
   function initTaskJqgrid(){
	   //$("#list1").tableDnD({scrollAmount:0}); 
	    AddUserMsg("text");
	   initFind_TaskAutocomplete();
	   initfindTask();
		initAddTaskDialog();
		$( "#Grop" ).buttonset();
     $("#Task_list1").jqGrid({
   	url:'../TaskHandle/editTask.jsp',
	datatype: "xml",
   	colNames:['ID','任务标题','内容','任务类型','添加时间','业务员','备注','删除'],
   	colModel:[
	    {name:'Task_ID', width:100, sortable:false,hidden:true},
		{name:'Task_Title', width:75, sortable:false},
   		{name:'Task_Content',index:'Task_Content', sortable:false},
		{name:'Task_Type',index:'Task_Type',sortable:false, width:50,},
   		{name:'Task_AddTime',index:'Task_AddTime', width:100},
		{name:'UP_ID', width:70,sortable:false},
   		{name:'Info',sortable:false,editable:true },
		{name:'del', width:50,sortable:false ,formatter:FmatterDel},
   	],
	//scroll: true,
   	rowNum:10,
   	autowidth: true,
	height:400,
   	rowList:[10,20,30],
	prmNames:{page:'page',rows:'rows',order: 'sord', search:'_search', nd:'nd', npage:null},
   	pager: jQuery('#Task_pager1'),
	loadCompele: $( "button").button(),
	loadError:   function(xhr,stu,e){alert(xhr.responseText);},
   	sortname: 'Task_ID',
    viewrecords: true,
    sortorder: "desc",
    caption:"XML Example",	
	forceFit : true, 
	cellEdit: true,
	cellsubmit: 'clientArray',
	afterEditCell: function (id,name,val,iRow,iCol){
		
	},
	afterSaveCell : function(rowid,name,val,iRow,iCol) {
		var myrow = jQuery('#Task_list1').jqGrid('getRowData',rowid);
		ModifyTask(myrow.Task_ID,name+"="+val);
	},
	
	onSelectRow: function(id){    
      
   },   
	gridComplete: function() {
    	$( "button").button();
    }, 
	//此事件在点击表格特定单元格时发生。rowid 为行ID；iCol 为列索引；cellcontent 为单元格中内容；e 点击事件对象
	onCellSelect:function(rowid,iCol,cellcontent,e){
		//alert("rowid="+rowid+" icol="+iCol+" cell="+cellcontent)
		if(iCol==8){
			
			if(cellcontent=='删除'){
				var aa= window.confirm("是否删除任务信息！");
			if (aa) {
			var myrow = jQuery('#Task_list1').jqGrid('getRowData',rowid);
			delTask(myrow.Task_ID);
			}
			}
		}
		},
	editurl:"../TaskHandle/editTask.jsp",
	
         
}).navGrid('#Task_pager1',{edit:false,add:false,del:false,search: false }).navButtonAdd('#Task_pager1',{   
   caption:"添加",    
   buttonicon:"ui-icon-add",    
   onClickButton: function(){    
    $('#Task-form').dialog('open').children('form')[0].reset();  
   },    

   position:"last"  
});	
//jQuery("#list1").jqGrid('inlineNav',"#pager1");
	   }
	   //通过订单表的行ID获取订单ID
	   function getTask_Titel_By_Row(rowid){
		   var myrow = jQuery('#Task_list1').jqGrid('getRowData',rowid);
			return myrow.Task_Titel;
		   }
	   
//修改用户信息
function ModifyTask(ID,url){
		$.ajax({
   type: "POST",
   async: false,
   dataType: "xml",
   url: "../TaskHandle/editTask.jsp?oper=edit",
   data: encodeURI("Task_ID="+ID+"&"+url),
   success: function(xmlResponse){
    //getStart(xmlResponse);
	var statuc=$(xmlResponse).find("statuc").text();	
	if(statuc=="true"){
		$("#Task_list1").trigger("reloadGrid");
		Toalert($(xmlResponse).find('msg').text());
		
		}else{
		Toalert($(xmlResponse).find('msg').text());
		}
 	},
		error: function(XMLHttpRequest, textStatus, errorThrown) {
                        alert("status:"+XMLHttpRequest.status+"readyState:"+XMLHttpRequest.readyState+"text:"+XMLHttpRequest.responseText);
                    },
 });
	}
	
	 function AddUserMsg(text){
	 $( ".Add_User_Msg" ).text( text )
				.addClass( "ui-state-highlight" );
			setTimeout(function() {
				$( ".Add_User_Msg" ).removeClass( "ui-state-highlight", 1500 );
			}, 500 );
	 }
	
	 //格式话产品状态类型
	function Fmatter_Task_Status(cellvalue, options, rowObject){
		  if(cellvalue=='0'){
			  //return "未确认下单";
			  return "<button >派送</button>";
		  }else if(cellvalue=='2'){
			  return "<button >派送</button>";
		  }else if(cellvalue=='2'){
			  return "已派送";
		  }else if(cellvalue=='3'){
			  return "已发货";
		  }else if(cellvalue=='4'){
			  return "已送货";
		  }else if(cellvalue=='5'){
			  return "已退货";
		  }
		}
//删除任务信息
function delTask(Task_ID){
		$.ajax({
   type: "POST",
   async: false,
   dataType: "xml",
   url: "../TaskHandle/delectTask.jsp",
   data: encodeURI("Task_ID="+Task_ID),
   success: function(xmlResponse){
    //getStart(xmlResponse);
	var statuc=$(xmlResponse).find("statuc").text();	
	if(statuc=="true"){
		Toalert($(xmlResponse).find('msg').text());
		$("#Task_list1").trigger("reloadGrid");
		}else{
		Toalert($(xmlResponse).find('msg').text());
		}
 	},
		error: function(XMLHttpRequest, textStatus, errorThrown) {
                        alert("status:"+XMLHttpRequest.status+"readyState:"+XMLHttpRequest.readyState+"text:"+XMLHttpRequest.responseText);
                    },
 });
	}

 //添加用户提示
 function AddUserMsg(text){
	 
	 $( "#Add_User_Msg" ).text( text )
				.addClass( "ui-state-highlight" );
			setTimeout(function() {
				$( "#Add_User_Msg" ).removeClass( "ui-state-highlight", 1500 );
			}, 500 );
	 }
 function Toalert(text){
	 alert(text);
	 }
	 
function FmatterDel(cellvalue, options, rowObject){
			return "删除";
		}
		
//初始化搜索任务下拉菜单
function initFind_TaskAutocomplete(){

	  $("#radio2").click(
		    function(){
				findTask(encodeURIComponent("拜访客户"));
			}
		);	
			$("#radio3").click(
		    function(){
				findTask(encodeURIComponent("今日工作内容"));
			}
		);	
			$("#radio4").click(
		    function(){
				findTask(encodeURIComponent("新任务"));
			}
		);
	
		$( "#TaskType" ).autocomplete({
			//source: "../userHandle/queryUser_Type.jsp",
			minLength: 0,
			selectedIndex:0,
			 source: function (request, response) {            
			 request.page = "1";  
			 request.rows= "100"; 
				$.ajax({
					url: "../TaskHandle/searchTask_Type.jsp",
					data: request,
					dataType: "json",
					success: function( data, status ) {
					
							response( data );
						
					},
					error: function() {
					
							response( [] );
						
					}
				});
			 },
			select: function( event, ui ) {
				//log( ui.item ?
				//	"Selected: " + ui.item.value + " aka " + ui.item.id :
				//	"Nothing selected, input was " + this.value );
				//alert(ui.item.id);
				 findTask();
			}
		});
				$( "#Add_Task_Type").autocomplete({
			//source: "../userHandle/queryUser_Type.jsp",
			minLength: 0,
			selectedIndex:0,
			 source: function (request, response) {            
			 request.page = "1";  
			 request.rows= "100"; 
				$.ajax({
					url: "../TaskHandle/searchTask_Type.jsp",
					data: request,
					dataType: "json",
					success: function( data, status ) {
					
							response( data );
						
					},
					error: function() {
					
							response( [] );
						
					}
				});
			 },
			select: function( event, ui ) {
				//log( ui.item ?
				//	"Selected: " + ui.item.value + " aka " + ui.item.id :
				//	"Nothing selected, input was " + this.value );
				//alert(ui.item.id);
				// findTask();
			}
		});
	
		var dates = $( "#Start_Task_AddTime, #End_Task_AddTime" ).datepicker({
			defaultDate: "+1w",
			changeMonth: true,
			numberOfMonths: 1,
			onSelect: function( selectedDate ) {
				var option = this.id == "Start_Task_AddTime" ? "minDate" : "maxDate",
					instance = $( this ).data( "datepicker" ),
					date = $.datepicker.parseDate(
						instance.settings.dateFormat ||
						$.datepicker._defaults.dateFormat,
						selectedDate, instance.settings );
				dates.not( this ).datepicker( "option", option, date );
			}
		});
	
	}
//初始化查询订单，指定送货按钮 
function initfindTask(){
			$("#find_Task").click(
		    function(){
				//alert($("#search").serialize());
	 findTask();
			}
		);	
	}
	//搜索用户事件
	function findTask(TaskType){
		/*获取select 选中的 text : 
	$("#ddlRegType").find("option:selected").text(); 
	获取select选中的 value: 
	$("#ddlRegType ").val(); 
	获取select选中的索引: 
	$("#ddlRegType ").get(0).selectedIndex; 
	设置select: 
	设置select 选中的索引： 
	$("#ddlRegType ").get(0).selectedIndex=index;//index为索引值*/
	//alert("userid="+$( "#userid").val()+"  username="+$( "#username").val()+"  usertype="+$( 			"#usertype").get(0).selectedIndex);
	var TaskTitle=encodeURIComponent($( "#TaskTitle").val());
	//var TaskType=encodeURIComponent($( "#TaskType").val());
	var Start_TaskAddTime=$("#Start_Task_AddTime").val();
	var End_TaskAddTime=$( "#End_Task_AddTime").val();
$("#Task_list1").jqGrid('setGridParam',{ url: '../TaskHandle/queryTask.jsp',
postData:{Task_Title:TaskTitle,Task_Type:TaskType,Start_Task_AddTime:Start_TaskAddTime,End_Task_AddTime:End_TaskAddTime},
}).trigger('reloadGrid'); 
		}

//添加任务
function addTask(Add_Task_Title,Add_Task_Content,Add_Task_Type,Add_Info){
		  	$.ajax({
   type: "POST",
   async: false,
   dataType: "xml",
   url: "../TaskHandle/editTask.jsp?oper=add",
   data: encodeURI("Task_Title="+Add_Task_Title+"&Task_Content="+Add_Task_Content+"&Task_Type="+Add_Task_Type+"&Info="+Add_Info),
   success: function(xmlResponse){
    //getStart(xmlResponse);
	var statuc=$(xmlResponse).find("statuc").text();	
	if(statuc=="true"){
		AddUserMsg($(xmlResponse).find('msg').text());
		$("#Task_list1").trigger("reloadGrid");
		}else{
		AddUserMsg($(xmlResponse).find('msg').text());
		}
 	},
		error: function(XMLHttpRequest, textStatus, errorThrown) {
                        alert("status:"+XMLHttpRequest.status+"readyState:"+XMLHttpRequest.readyState+"text:"+XMLHttpRequest.responseText);
                    },
 });
	}

//初始化添加用户产品价格对话框
function initAddTaskDialog(){
				$( "#Task-form" ).dialog({
			autoOpen: false,
			height: 400,
			width: 350,
			modal: true,
			buttons: {
				"添加": function() {
			addTask($( "#Add_Task_Title" ).val(),$( "#Add_Task_Content" ).val(),$( "#Add_Task_Type" ).val(),$( "#Add_Info" ).val());
				},
				//"取消": function() {
				//	$( this ).dialog( "close" );
				//}
			},
			"取消": function() {
				//allFields.val( "" ).removeClass( "ui-state-error" );
			}
		});
	}
// JavaScript Document